package com.lianwei.hospital.controller;


import com.lianwei.hospital.Service.BedService;
import com.lianwei.hospital.Service.Impl.BedInfoImpl;
import com.lianwei.hospital.module.entity.BedInfo;
import com.lianwei.hospital.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/bed")
public class BedInfoController {
    @Autowired
    private BedService bedService;

    @GetMapping("/selectById")
    public Result<BedInfo> Select(Integer i) throws Exception {
        System.out.println(i+"\n\n");
        BedInfo bedInfo = bedService.selectByPrimaryKey(i);
        return Result.buildResult(Result.Status.OK,bedInfo);
    }

    @PutMapping
    public Result<List<BedInfo>> Insert(@RequestBody BedInfo bedInfo) throws Exception {
        System.out.println(bedInfo);
        if(bedService.insert(bedInfo)){
            List<BedInfo> bedInfoList = bedService.selectAll();
            return Result.buildResult(Result.Status.OK,bedInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @DeleteMapping
    public Result<List<BedInfo>> Delete(@RequestBody BedInfo bedInfo) throws Exception {
        System.out.println(bedInfo);
        if(bedService.deleteByPrimaryKey(bedInfo.getId())){
            List<BedInfo> bedInfoList = bedService.selectAll();
            return Result.buildResult(Result.Status.OK,bedInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @PostMapping
    public Result<List<BedInfo>> Update(@RequestBody BedInfo bedInfo) throws Exception {
        System.out.println(bedInfo);
        if(bedService.updateByPrimaryKey(bedInfo)){
            List<BedInfo> bedInfoList = bedService.selectAll();
            return Result.buildResult(Result.Status.OK,bedInfoList);
        }
        return Result.buildResult(Result.Status.BAD_REQUEST);
    }

    @GetMapping("/selectAll")
    public String abc() throws Exception {
        List<BedInfo> bedInfoList = bedService.selectAll();
        System.out.println(bedInfoList);
        return "abc";
    }



}
